const DATE_REG = /^(\d{4})(\d{2})(\d{2})/g

//转换成日期格式 YYYY-MM-DD
let dateStr = (value) => {
    return value.replace(DATE_REG,'$1-$2-$3')
}

// 正则表达式使用圆括号进行组匹配。
// 使用exec方法，就可以将这三组匹配结果提取出来。
/*const RE_DATE = /(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/;

const matchObj = RE_DATE.exec('1999-12-31');
const year = matchObj.groups.year; // 1999
const month = matchObj.groups.month; // 12
const day = matchObj.groups.day; // 31*/


//返回日期所在星期几
let dateWeek = ['星期一','星期二','星期三','星期四','星期五','星期六','星期日']
let dateWeekDay = (value) => {
    return dateWeek[new Date(Date.parse(value.replace(/\-/g,'/'))).getDay()-1]
}

//时间格式过滤2018/02/03 
let formatDate = (date) => { 
    const year = date.getFullYear();
    const month = (date.getMonth() + 1) < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1;
    const day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
    const nowDate = year + '-' + month + '-' + day;
    return nowDate;
}

export {dateStr,dateWeekDay,formatDate}